<!doctype html>
<html lang="zh-CH">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	{{--<meta name="viewport" content="width=device-width, initial-scale=1">--}}
	<title>央票通</title>
	<link rel="stylesheet" href="./resource/css/index.css">
	<link rel="stylesheet" href="./resource/css/user.css">
</head>
<body>
<?php
	$user_info = session_get(UserEnum::USER_INFO_SESSION_KEY);
	$user  = UserService::instance()->GetUserInformation();
?>
<!-- 头部 -->
@include('common.index_head')
<!-- 个人中心 -->
<div class="cont-user">
	<!-- 个人中心头部 -->
	@include('common.user_head')
	<div class="user-center">
		<div class="main">
			<!-- 个人中心列表 -->
			@include('common.user_left')
			<div class="user-container left">
				<div class="user-title user-password">
					<div class="title">
						<div class="h left">密码管理</div>
					</div>
					<div class="user-box">
						<ul class="pass-ul">
							<li class="active"><a href="javascript:;">登录密码</a></li>
							@if($user->pay_pwd=='')

							@else
								<li><a href="javascript:;">支付密码</a></li>
							@endif
						</ul>
						<div class="pass-main">
							<div class="pass-cont">
								<form action="up_login_pwd" class="form" method="post" onsubmit="return check_all1()">
									<div class="form-group">
										<label for="" class="left control-label">当前密码：</label>
										<input type="password" class="left form-control" placeholder="请填写当前密码" name="now_pwd" id="now_pwd" onblur="check_new()"><span id="t_now"></span>
									</div>
									<div class="form-group">
										<label for="" class="left control-label">新密码：</label>
										<input type="password" class="left form-control" placeholder="请填写新密码" name="new_pwd" id="new_pwd"><span id="t_new"></span>
									</div>
									<div class="form-group">
										<label for="" class="left control-label">确认新密码：</label>
										<input type="password" class="left form-control" placeholder="请确认新密码" name="sure_pwd" id="sure_pwd"><span id="t_sure"></span>
									</div>
									<div class="form-group form-code">
										<label for="" class="left control-label">验证码：</label>
										<input type="text" class="left form-control" placeholder="请填写验证码" name="captcha" id="captcha" onblur="check_captcha()"><span id="t_captcha"></span>
										<div class="left code">
											<img onclick="this.src='/captcha?'+ Math.random()"  src="/captcha">
										</div>
									</div>
									<div class="form-group">
										<div class="btn-box">
											<button type="submit" class="btn btn-default" style="margin-right: 10px">确认修改</button>
											<button type="reset" class="btn btn-remove">重置</button>
										</div>
									</div>
								</form>		
							</div>
							<div class="pass-cont">
								<form action="/up_pay_pwd" class="form" method="post" onsubmit="return check_all2()">
									<div class="form-group">
										<label for="" class="left control-label">手机号码：</label>
										<div class="left user-tel"> {{substr_replace($user_info->mobile,'****',3,4)}}</div>
										<input type="hidden" value="{{$user_info->mobile}}" name="mobile" id="mobile">
									</div>
									<div class="form-group form-code">
										<label for="" class="left control-label">验证码：</label>
										<input type="text" class="left form-control" placeholder="请填写验证码" name="pay_captcha" id="pay_captcha" onblur="check_pay()"><span id="t_pay_captcha"></span>
										<div class="left code">
											<img onclick="this.src='/captcha?'+ Math.random()"  src="/captcha">
										</div>
									</div>
									<div class="form-group form-code">
										<label for="" class="left control-label">短信验证码：</label>
										<input type="text" class="left form-control" placeholder="请填写验证码" name="news_captcha" id="news_captcha" onblur="check_news()">
										<span class="left code"  id="f_captcha">获取短信验证码</span><span id="t_news"></span>
									</div>
									<div class="form-group">
										<label for="" class="left control-label">设置新密码：</label>
										<input type="text" class="left form-control" placeholder="请填写新密码" name="pay_new_pwd" id="pay_new_pwd"><span id="t_new_pay"></span>
									</div>
									<div class="form-group">
										<label for="" class="left control-label">确认新密码：</label>
										<input type="text" class="left form-control" placeholder="请确认新密码" name="sure_new_pwd" id="sure_new_pwd"><span id="t_new_sure"></span>
									</div>
									<div class="form-group">
										<div class="btn-box">
											<button type="submit" class="btn btn-pay">确认修改</button>
										</div>
									</div>
								</form>		
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<!-- footer -->
@include('common.index_foot')
<script src="./resource/js/jquery-1.11.3.min.js"></script>
<script src="./resource/js/index.js"></script>
<script src="./resource/js/user.js"></script>
<script>
	function check_new()
	{
		var now_pwd   = document.getElementById('now_pwd').value;
		var status	  = false;
			var ajax = new XMLHttpRequest();
			ajax.onreadystatechange = function () {
				if (ajax.readyState == 4) {
					if (ajax.responseText == 1) {
						document.getElementById("t_now").innerHTML = "<span style='color:green'>√</span>";
						status = true
					} else {
						document.getElementById("t_now").innerHTML = "<span style='color:red'>当前密码错误</span>";
					}
				}
			}
			//与服务器建立连接
			ajax.open('post', '/js_up_login_pwd', false);
			ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			//处理请求
			ajax.send('&now_pwd=' + now_pwd);
			return status
	}

	function check_captcha()
	{
		var captcha   = document.getElementById('captcha').value;
		var status	  = false;
		var ajax = new XMLHttpRequest();
		ajax.onreadystatechange = function () {
			if (ajax.readyState == 4) {
				if (ajax.responseText == 1) {
					document.getElementById("t_captcha").innerHTML = "<span style='color:green'>√</span>";
					status = true
				}else{
					document.getElementById("t_captcha").innerHTML = "<span style='color:red'>验证码错误</span>";
				}
			}
		}
		//与服务器建立连接
		ajax.open('post', '/js_up_login_pwd', false);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		//处理请求
		ajax.send('captcha=' + captcha);
		return status
	}

	function check_all1()
	{
		var now_pwd   = document.getElementById('now_pwd').value;
		var new_pwd   = document.getElementById('new_pwd').value;
		var sure_pwd  = document.getElementById('sure_pwd').value;
		var reg=/^\w{6,16}$/;
			if(reg.test(new_pwd)){
				if(now_pwd!=new_pwd){
					document.getElementById("t_new").innerHTML = "<span style='color:green'>√</span>";
					if(new_pwd==sure_pwd){
						document.getElementById("t_sure").innerHTML = "<span style='color:green'>√</span>";
					}else{
						document.getElementById("t_sure").innerHTML = "<span style='color:red'>俩次密码不一致</span>";
						return false;
					}
				}else{
					document.getElementById("t_new").innerHTML = "<span style='color:red'>不能和以前密码重复</span>";
					return false;
				}
			}else{
				document.getElementById("t_new").innerHTML = "<span style='color:red'>新密码错误</span>";
				return false;
			}
		return (check_new()&&check_captcha())
	}

	function check_pay()
	{
		var pay_captcha = document.getElementById('pay_captcha').value;
		var status = false;
		var ajax = new XMLHttpRequest();
		ajax.onreadystatechange = function () {
			if (ajax.readyState == 4) {
				if (ajax.responseText == 1) {
					document.getElementById("t_pay_captcha").innerHTML = "<span style='color:green'>√</span>";
					status = true
				}else{
					document.getElementById("t_pay_captcha").innerHTML = "<span style='color:red'>验证码错误</span>";
				}
			}
		}
		//与服务器建立连接
		ajax.open('post', '/js_up_pay_pwd', false);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		//处理请求
		ajax.send('pay_captcha=' + pay_captcha);
		return status;
	}

	//获取短信验证码
	$('#f_captcha').bind('click',function foo() {
		var mobile = document.getElementById('mobile').value;
		if(check_pay()){
			var wait = 60;
			var int = function fetch_captcha() {
				if (wait == 0) {
					$("#f_captcha").bind("click", foo);
					$('#f_captcha').html('获取验证码');
					clearInterval(a)
					wait = 60;
				}
				else {
					$('#f_captcha').unbind("click", foo);
					$('#f_captcha').html("重新发送(" + wait + ")");
					wait--;
				}
			}
			var a = setInterval(int, 1000);
			$.ajax({
				url: "/verify_news",
				type: "POST",
				data: "mobile=" + mobile,
				success: function (msg) {
					if (msg == 10000) {
						$("#t_news").html("<span style='color:green'>验证码发送成功,10分钟内输入有效</span>");
					}else if(msg == 160040){
						$("#t_news").html("<span style='color:red'>您当日验证码发送次数过多</span>");
						window.clearInterval(a);//停止计时器
						$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
						$(".form-code span.code").html("获取短信验证码");
						return false;
					}else{
						$("#t_news").html("<span style='color:red'>验证码发送错误</span>");
						window.clearInterval(a);//停止计时器
						$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
						$(".form-code span.code").html("获取短信验证码");
						return false;
					}
				}
			});
		}
	})



	function check_news()
	{
		var news_captcha = document.getElementById('news_captcha').value;
		var status = false;
		var ajax = new XMLHttpRequest();
		ajax.onreadystatechange = function () {
			if (ajax.readyState == 4) {
				if (ajax.responseText == 1) {
					document.getElementById("t_news").innerHTML = "<span style='color:green'>√</span>";
					status = true
				}else{
					document.getElementById("t_news").innerHTML = "<span style='color:red'>短信验证码错误</span>";
				}
			}
		}
		//与服务器建立连接
		ajax.open('post', '/js_up_pay_pwd', false);
		ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		//处理请求
		ajax.send('news_captcha=' + news_captcha);
		return status;

	}


	function check_all2()
	{
		var pay_new_pwd   = document.getElementById('pay_new_pwd').value;
		var sure_new_pwd   = document.getElementById('sure_new_pwd').value;
		var reg = /^\d{6}$/
		if(reg.test(pay_new_pwd)){
			document.getElementById("t_new_pay").innerHTML = "<span style='color:green'>√</span>";
			if(pay_new_pwd==sure_new_pwd){
				document.getElementById("t_new_sure").innerHTML = "<span style='color:green'>√</span>";
				return true;
			}else{
				document.getElementById("t_new_sure").innerHTML = "<span style='color:red'>俩次密码不一致</span>";
				return false;
			}
		}else{
			document.getElementById("t_new_pay").innerHTML = "<span style='color:red'>密码为6位数字</span>";
			return false;
		}

		return (check_news()&&check_pay())
	}
</script>
</body>
</html>